from django.db import models

# Create your models here.


from . import random_name
from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    telephone = models.CharField(max_length=11, unique=True, )
    # 需要pillow包的支持
    icon = models.ImageField(upload_to='icon', default='icon/default.png')
    sex = models.CharField(max_length=5, null=True)
    # 昵称
    nicknames = models.CharField(max_length=52, null=True, unique=True, default=random_name.fullname())
    # 角色
    roles = models.CharField(max_length=16, null=True)
    # 地区
    region = models.CharField(max_length=128, null=True)
    birthdays = models.DateField(null=True)
    # 个性签名
    signature = models.CharField(max_length=256, null=True)

    class Meta:
        db_table = 'photo_user'  # 指定表名为
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


# 作品表
class Article(models.Model):
    # title = models.CharField(max_length=32,null=True)
    themetext = models.TextField()
    create_time = models.DateTimeField(auto_now_add=True)
    up_num = models.IntegerField(default=0, null=True)
    down_num = models.IntegerField(default=0, null=True)
    Comment_num = models.IntegerField(default=0, null=True)
    # 浏览量
    reads = models.IntegerField(default=0, null=True)
    user = models.ForeignKey(to='User', on_delete=models.CASCADE)
    # 主题
    theme = models.CharField(max_length=32, null=True)

    # 多对多用中介模型创建

    def __str__(self):
        return self.theme


# 评论表
class Comment(models.Model):
    create_time = models.DateTimeField(auto_now_add=True, null=True)
    content = models.CharField(max_length=256, null=True)
    # 表关联
    user = models.ForeignKey(to='User', on_delete=models.CASCADE, null=True)
    article = models.ForeignKey(to='Article', on_delete=models.CASCADE, null=True)
    Appointment = models.ForeignKey(to='Appointment', on_delete=models.CASCADE, null=True)
    Tutotial = models.ForeignKey(to='Tutotial', on_delete=models.CASCADE, null=True)
    Comment_id = models.ForeignKey(to='self', on_delete=models.CASCADE, null=True)


# 点赞点踩表
class UpAndDown(models.Model):
    is_up = models.BooleanField()
    create_time = models.DateTimeField(auto_now_add=True, null=True)
    # 关联表
    user = models.ForeignKey(to='User', on_delete=models.CASCADE, null=True)
    article = models.ForeignKey(to='Article', on_delete=models.CASCADE, null=True)


# 图片表
class Image(models.Model):
    image = models.ImageField(verbose_name='作品图', upload_to='photo', help_text='图片尺寸(注释)', null=True)
    article = models.ForeignKey(to='Article', on_delete=models.CASCADE, null=True)
    appointment = models.ForeignKey(to='Appointment', on_delete=models.CASCADE, null=True)
    tutotial = models.ForeignKey(to='Tutotial', on_delete=models.CASCADE, null=True)
    venue = models.ForeignKey(to='Venue', on_delete=models.CASCADE, null=True)


# 聊天表
class Talking(models.Model):
    create_time = models.DateTimeField(auto_now_add=True, null=True)
    content = models.CharField(max_length=256, null=True)
    user_id = models.ForeignKey(to='User', on_delete=models.CASCADE)


# 场地表
class Venue(models.Model):
    fieldname = models.CharField(max_length=64)
    fieldAdress = models.CharField(max_length=64)
    introduce = models.TextField()
    fieldType = models.CharField(max_length=16)
    # 主题
    suitable = models.CharField(max_length=32, null=True)
    user = models.ForeignKey(to='User', on_delete=models.CASCADE, null=True)

    create_time = models.DateTimeField(auto_now_add=True)
    up_num = models.IntegerField(default=0, null=True)
    down_num = models.IntegerField(default=0, null=True)
    Comment_num = models.IntegerField(default=0, null=True)
    # 浏览量
    reads = models.IntegerField(default=0, null=True)


# 约拍表
class Appointment(models.Model):
    # 主题
    subject = models.CharField(max_length=32, null=True)
    # 内容 要求
    aprequirement = models.CharField(max_length=256, null=True)
    # 时间
    time = models.DateTimeField(auto_now_add=True, null=True)
    apTime = models.CharField(max_length=64)
    apAdress = models.CharField(max_length=256, null=True)
    # 约拍角色(模特或摄影师)
    apType = models.CharField(max_length=16, null=True)
    # 约拍类型(情侣或风景等)
    aptheme = models.CharField(max_length=32, null=True)
    user = models.ForeignKey(to='User', on_delete=models.CASCADE)


# 教程表
class Tutotial(models.Model):
    user = models.ForeignKey(to='User', on_delete=models.CASCADE)
    # 教程内容
    tocontent = models.CharField(max_length=256, null=True)
    time = models.DateTimeField(auto_now_add=True, null=True)
    # 教程主题
    tttheme = models.CharField(max_length=32, null=True)


# 收藏表
class Collection(models.Model):
    user = models.ForeignKey(to='User', on_delete=models.CASCADE)
    article = models.ForeignKey(to='Article', on_delete=models.CASCADE)
    # 教程表id
    tutotial = models.ForeignKey(to='Tutotial', on_delete=models.CASCADE)
    appointment = models.ForeignKey(to='Appointment', on_delete=models.CASCADE)
